﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Spring.Transaction.Interceptor;
using Dao;
using System.Data;

namespace Service
{
    public class UserService : IUserService
    {
        public IUserDao UserDao { get; set; }

        public IAccountDao AccountDao { get; set; }

        [Transaction]
        public void SaveData(string name, int age, string accountName)
        {
            UserDao.Create(name, age);
            AccountDao.Create(accountName, name);
        }

        //[Transaction]
        //public void SaveData(string name, int age, string accountName)
        //{
        //    try
        //    {
        //        UserDao.Create(name, age);
        //        AccountDao.Create(accountName, name);
        //    }
        //    catch (Exception ex)
        //    {
        //        Console.WriteLine(ex);
        //    }
        //}

        [Transaction]
        public void DeleteData(string name)
        {
            UserDao.Delete(name);
            throw new Exception("测试数据是否回滚");
            AccountDao.Delete(name);
        }

        [Transaction(ReadOnly = true)]
        public DataSet Get(string name)
        {
            return UserDao.Get(name);
        }
    }
}
